package org.lotterm.jconcat;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class ImagePanel extends JPanel {
	
	private boolean deleted=false;
	private final ImageIcon deletedIcon=new ImageIcon("/home/thomas/Desktop/deleted.png");
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Image img;

	public ImagePanel(String img) {
		this(new ImageIcon(img).getImage());
	}

	public ImagePanel(Image img) {
		this.img = img;
		
		this.setMinimumSize(new Dimension(img.getWidth(null)+5,img.getHeight(null)+5));
		this.setPreferredSize(new Dimension(img.getWidth(null)+5,img.getHeight(null)+5));
		
		this.repaint();
	}

	public void paintComponent(Graphics g) {
		int compX=this.getSize().width;
		int compY=this.getSize().height;
		
		int imgX=img.getWidth(null);
		int imgY=img.getHeight(null);
		
		int posX=(compX-imgX)/2;
		int posY=(compY-imgY)/2;
		
		g.drawImage(img, posX, posY, null);
		if(deleted) {
			g.setColor(new Color(255, 10, 10, 20));
			g.fillRect(posX, posY, imgX, imgY/2);
			g.setColor(new Color(255, 10, 10, 40));
			g.fillRect(posX, posY+imgY/2, imgX, imgY/2);
			g.drawImage(deletedIcon.getImage(),this.getWidth()/2-deletedIcon.getIconWidth()/2,this.getHeight()/2-deletedIcon.getIconHeight()/2,null);
		}
		
	}
	
	public void delete() {
		deleted=true;
		repaint();
	}
	
	public void undelete() {
		deleted=false;
		repaint();
	}

}
